<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>同友加密</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <link rel="stylesheet" href="../static/layui/css/layui.css"/>
    <script type="text/javascript" src="../static/jquery-3.1.0.js"></script>
    <script type="text/javascript" src="../static/layui/layui.js"></script>
    <style>
        .layui-input-block {
            margin-left: 150px;
        }
        .layui-form-label {
            width: 120px;
        }
    </style>
</head>
<body>
    <div style="width: 100%;height: 200px;line-height: 200px;font-size: 40px;text-align: center;">辽宁同友收费系统软加密生成工具</div><!-- 辽宁同友软加密生成工具 -->
    <div style="margin: 0 100px 0 100px;">
        <form id="dataForm" class="layui-form" action="" lay-filter="dataForm">
            <blockquote class="layui-elem-quote">
                机器指纹
            </blockquote>
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="color: red;">机器MAC码*</label>
                        <div class="layui-input-block">
                            <input type="text" name="mac" lay-verify="required" placeholder="请输入服务器机器MAC码" class="layui-input"/>
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <button type="button" class="layui-btn layui-btn-primary layui-border-blue" onclick="getLocalMac()">获取本机机器MAC码</button>
                </div>
            </div>
            <br/><br/>
            <blockquote class="layui-elem-quote">
                收费平台加密
            </blockquote>
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md12">
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="color: red;">控制方式*</label>
                        <div class="layui-input-block">
                            <input type="radio" name="platfprmType" value="0" title="不控制" checked>
                            <input type="radio" name="platfprmType" value="1" title="用户数控制">
                            <input type="radio" name="platfprmType" value="2" title="租赁时间控制">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">最大用户数</label>
                        <div class="layui-input-block">
                            <input id="userNumber" name="userNumber" type="number" lay-affix="number" lay-precision="0" placeholder="请输入最大用户数" value="0" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">租赁开始时间</label>
                        <div class="layui-input-block">
                            <input id="platformStartDate" name="platformStartDate" type="text" placeholder="请选择" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">租赁结束时间</label>
                        <div class="layui-input-block">
                            <input id="platformEndDate" name="platformEndDate" type="text" placeholder="请选择" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <br/><br/>
            <blockquote class="layui-elem-quote">
                学生缴费移动端加密
            </blockquote>
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md12">
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="color: red;">控制方式*</label>
                        <div class="layui-input-block">
                            <input type="radio" name="studentType" value="0" title="不控制" checked>
                            <input type="radio" name="studentType" value="1" title="学生数控制">
                            <input type="radio" name="studentType" value="2" title="租赁时间控制">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">最大学生数</label>
                        <div class="layui-input-block">
                            <input id="studentNumber" name="studentNumber" type="number" lay-affix="number" placeholder="请输入最大学生数" value="0" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">租赁开始时间</label>
                        <div class="layui-input-block">
                            <input id="studentStartDate" name="studentStartDate" type="text" placeholder="请选择" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">租赁结束时间</label>
                        <div class="layui-input-block">
                            <input id="studentEndDate" name="studentEndDate" type="text" placeholder="请选择" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <br/><br/>
            <blockquote class="layui-elem-quote">
                校外人员缴费移动端加密
            </blockquote>
            <div class="layui-row layui-col-space10">
                <div class="layui-col-md12">
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="color: red;">控制方式*</label>
                        <div class="layui-input-block">
                            <input type="radio" name="outerType" value="0" title="不控制" checked>
                            <input type="radio" name="outerType" value="1" title="注册数控制">
                            <input type="radio" name="outerType" value="2" title="租赁时间控制">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">最大注册数</label>
                        <div class="layui-input-block">
                            <input id="outerNumber" name="outerNumber" type="number" lay-affix="number" placeholder="请输入最大注册数" value="0" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">租赁开始时间</label>
                        <div class="layui-input-block">
                            <input id="outerStartDate" name="outerStartDate" type="text" placeholder="请选择" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">租赁结束时间</label>
                        <div class="layui-input-block">
                            <input id="outerEndDate" name="outerEndDate" type="text" placeholder="请选择" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div style="margin-top: 50px;margin-left: 30%;margin-right: 30%;">
        <div class="layui-row layui-col-space10">
            <div class="layui-col-md6">
                <button type="button" class="layui-btn layui-btn-fluid" style="background-color: #16b777;" onclick="exportLicense()">导出加密文件</button>
            </div>
            <div class="layui-col-md6">
                <button type="button" class="layui-btn layui-bg-blue layui-btn-fluid">清空表单</button>
            </div>
        </div>
    </div>
    <script>
        let laydate = layui.laydate;
        let form = layui.form;
        let layer = layui.layer;

        laydate.render({
            elem: '#platformStartDate'
        });
        laydate.render({
            elem: '#platformEndDate'
        });
        laydate.render({
            elem: '#studentStartDate'
        });
        laydate.render({
            elem: '#studentEndDate'
        });
        laydate.render({
            elem: '#outerStartDate'
        });
        laydate.render({
            elem: '#outerEndDate'
        });

        function exportLicense() {
            let data = form.val('dataForm');
            // console.log(data);
            if (data.mac == undefined || data.mac == null || data.mac == '') {
                layer.msg('请输入机器MAC码！', {offset: '16px'});
                return;
            }

            if (data.platfprmType == 1) {
                if (data.userNumber <= 0) {
                    layer.msg('最大用户数不能小于0！', {offset: '16px'});
                    return;
                }
                if (isInteger(data.userNumber)) {
                    layer.msg('最大用户数必须为整数！', {offset: '16px'});
                    return;
                }
            }
            if (data.platfprmType == 2) {
                if (data.platformStartDate == '' || data.platformEndDate == '') {
                    layer.msg('收费平台租赁开始时间、结束时间不能为空！', {offset: '16px'});
                    return;
                }
            }

            if (data.studentType == 1) {
                if (data.studentNumber <= 0) {
                    layer.msg('最大学生数不能小于0！', {offset: '16px'});
                    return;
                }
                if (isInteger(data.studentNumber)) {
                    layer.msg('最大学生数必须为整数！', {offset: '16px'});
                    return;
                }
            }
            if (data.studentType == 2) {
                if (data.studentStartDate == '' || data.studentEndDate == '') {
                    layer.msg('学生缴费移动端租赁开始时间、结束时间不能为空！', {offset: '16px'});
                    return;
                }
            }

            if (data.outerType == 1) {
                if (data.outerNumber <= 0) {
                    layer.msg('最大注册数不能小于0！', {offset: '16px'});
                    return;
                }
                if (isInteger(data.outerNumber)) {
                    layer.msg('最大注册数必须为整数！', {offset: '16px'});
                    return;
                }
            }
            if (data.outerType == 2) {
                if (data.outerStartDate == '' || data.outerEndDate == '') {
                    layer.msg('外部人员缴费移动端租赁开始时间、结束时间不能为空！', {offset: '16px'});
                    return;
                }
            }

            let index = layer.load(2);
            $.ajax({
                type: 'post',
                url: '/createLicense',
                data: data,
                success: function(rs) {
                    if (rs.code == 200) {
                        layer.close(index);
                        window.open("/exportLicense?uid=" + rs.data);
                    }
                }
            })
        }

        function isInteger(num) {
            return parseInt(num) === num;
        }

        function getLocalMac() {
            let index = layer.load(2);
            $.ajax({
                type: 'post',
                url: '/getLocalMac',
                success: function(rs) {
                    if (rs.code == 200) {
                        layer.close(index);
                        layer.alert(rs.data + "（生产环境请从服务器获取！）", {title: "本机机器码"});
                    }
                }
            })
        }
    </script>
</body>
</html>
